package com.message.tcp.ip.application.ui.component;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import com.message.tcp.ip.ui.member.EnviromentDailog;

public class MyFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3140890828074711569L;
	private JMenuBar mainMenuBar;
	private JMenu fileMenu;
	private JMenuItem exitMenuItem;
	private JMenu modeMenu;
	private JMenuItem issuerMenuItem;
	private JMenuItem acquirerMenuItem;
	
	private JMenu executeMenu;
	private JMenuItem executeMenuItem;
	private JMenuItem stopMenuItem;
	
	private JMenu logMenu;
	private JMenuItem logMenuItem;
	
	private JMenu parameterMenu;
	private JMenuItem accountMenuItem;
	private JMenuItem memberMenuItem;
	private JMenuItem binMenuItem;
	private JMenuItem txnMenuItem;
	private JMenuItem deMenuItem;
	private JMenuItem keyMenuItem;
	private JMenuItem networkMenuItem;
	
	private JMenu helpMenu;
	private JMenuItem manualMenuItem;
	private JPanel blankPanel;
	private AcquirerPanel acquirerPanel;
	private IssuerPanel issuerPanel;
	private JPanel panel;
	private CardLayout cardLayout;
	
	private EnviromentDailog enviromentDialog;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MyFrame frame = new MyFrame();
					
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	/**
	 * Create the frame.
	 */
	public MyFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 700);
		mainMenuBar = new JMenuBar();
		setJMenuBar(mainMenuBar);
		
		fileMenu = new JMenu("File");
		exitMenuItem = new JMenuItem("Exit");
		fileMenu.add(exitMenuItem);
		
		modeMenu = new JMenu("Mode");
		issuerMenuItem = new JMenuItem("issuer");
		issuerMenuItem.addActionListener(new IssuerMenuItemAction());
		acquirerMenuItem = new JMenuItem("acquirer");
		acquirerMenuItem.addActionListener(new AcquirerMenuItemAction());
		modeMenu.add(issuerMenuItem);
		modeMenu.add(acquirerMenuItem);
		
		executeMenu = new JMenu("Execute");
		executeMenuItem = new JMenuItem("execute");
		stopMenuItem = new JMenuItem("stop");
		
		executeMenu.add(executeMenuItem);
		executeMenu.add(stopMenuItem);
		
		parameterMenu = new JMenu("Parameter");
		accountMenuItem = new JMenuItem("account");
		memberMenuItem = new JMenuItem("member");
		memberMenuItem.addActionListener(new ParameterMenuAction());
		binMenuItem = new JMenuItem("bin");
		deMenuItem = new JMenuItem("data element");
		txnMenuItem = new JMenuItem("transaction");
		keyMenuItem = new JMenuItem("key");
		networkMenuItem = new JMenuItem("network");
		
		parameterMenu.add(memberMenuItem);
		parameterMenu.add(accountMenuItem);
		parameterMenu.add(binMenuItem);
		parameterMenu.add(txnMenuItem);
		parameterMenu.add(deMenuItem);
		parameterMenu.add(keyMenuItem);
		parameterMenu.add(networkMenuItem);
		
		logMenu = new JMenu("Logging");
		logMenuItem = new JMenuItem("Path");
		logMenu.add(logMenuItem);
		
		helpMenu = new JMenu("Help");
		manualMenuItem = new JMenuItem("manual");
		
		helpMenu.add(manualMenuItem);
		
		mainMenuBar.add(fileMenu);
		mainMenuBar.add(modeMenu);
		mainMenuBar.add(executeMenu);
		mainMenuBar.add(logMenu);
		mainMenuBar.add(parameterMenu);
		mainMenuBar.add(helpMenu);
		
		// Main Panel
		panel = new JPanel();
		cardLayout = new CardLayout();
		panel.setLayout(cardLayout);
		// Blank Panel
		blankPanel = new JPanel();
		// Acquire Panel
		acquirerPanel = new AcquirerPanel();
		// Issuer Panel
		issuerPanel = new IssuerPanel();
		// add Mode Panel to Main Panel
		panel.add(blankPanel, "blankMode");
		panel.add(acquirerPanel, "acquirerMode");
		panel.add(issuerPanel, "issuerMode");
		this.getContentPane().add(panel,BorderLayout.CENTER);
	}
	
	private class IssuerMenuItemAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent event) {
			cardLayout.show(panel, "issuerMode");
		}
		
	}
	private class AcquirerMenuItemAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			cardLayout.show(panel, "acquirerMode");
		}
		
	}
	
	private class ParameterMenuAction implements ActionListener{
		
		@Override
		public void actionPerformed(ActionEvent e) {
			enviromentDialog = new EnviromentDailog();
			enviromentDialog.setVisible(true);
		}
		
	}
}
